/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.univalle.persistencia;

import co.edu.univalle.modelo.Ciaenvios;
import co.edu.univalle.modelo.Clientes;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author valentina
 */
@Stateless
public class CiaenviosDAO implements ICiaenviosDAO {
    
      @PersistenceContext
    private EntityManager entityManager;


    @Override
    public void registrar(Ciaenvios ciaenvios) {
        try{
         entityManager.persist(ciaenvios);
     }
     catch (RuntimeException e){
     throw e;
    }
    }

    @Override
    public void modificar(Ciaenvios ciaenvios) {
        try{
         entityManager.merge(ciaenvios);
     }
     catch (RuntimeException e){
     throw e;
     }
  }

    
    
    @Override
    public void eliminar(Ciaenvios ciaenvios) {
         try{
         entityManager.remove(ciaenvios);
     }
     catch (RuntimeException e){
     throw e;
    }
  }
    
    

    @Override
    public List<Ciaenvios> consultar() {
                     try{
                String jpql = "SELECT c FROM Ciaenvios c";
                Query query = entityManager.createQuery(jpql);
                return query.getResultList();
         
     }
     catch (RuntimeException e){
     throw e;
}
    }

   

    @Override
    public Ciaenvios consultarPorIdciaenvio(Integer idciaenvios) {
       try{
                    return entityManager.find(Ciaenvios.class, idciaenvios);
     }
                
     catch (RuntimeException e){
     throw e;
       
        }
    }
    }

